package com.zsl.provider.service;


import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.shared.Applications;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * eureka 服务
 */
@Service
public class EurekaService {

	@Resource
	private EurekaClient eurekaDiscoveryClient;

	@Resource
	private DiscoveryClient springDiscoveryClient;

	/**
	 * 通过euraka自身clien获取信息
	 * @return
	 */
	public String getInfoByEuraka(){
		Applications applications = eurekaDiscoveryClient.getApplications();
		return applications.getRegisteredApplications().get(0).getName();

	}

	/**
	 * 通过spring接口获取euraka信息
	 * @return
	 */
	public String getInfoBySpring(){
		return springDiscoveryClient.getServices().get(0);
	}
}
